package action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.collections4.map.HashedMap;

import com.google.gson.Gson;

import pojo.Answer;
import pojo.AnswerComment;
import pojo.Article;
import pojo.ArticleComment;
import pojo.BaseDataPojo;
import pojo.Question;
import pojo.Resource;
import pojo.ResourceComment;
import service.ForumService;
import serviceImpl.ForumServiceImpl;


@WebServlet("/ForumServlet")
public class ForumServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       

    public ForumServlet() {
        super();
    }


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		doPost(request, response);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String mark = request.getParameter("mark");
		switch(mark) {
		
		
		case "getAllQuestion":   // 获取所有问答区的问题
			getAllQuestion(request,response);
			break;
		case "getAnswerByqid":   // 获取所有问答区的问题
			getAnswerByqid(request,response);
			break;
		case "getAnswerComment":  // 根据aid获取用户评论
			getAnswerComment(request,response);
			break;
		case "getAllArticle":  // 获取经验区的所有经验贴
			getAllArticle(request,response);
			break;
		case "getArticleComment":  // 根据artid获取用户评论
			getArticleComment(request,response);
			break;
		case "getAllResource":  // 根据资料区的所有资料贴
			getAllResource(request,response);
			break;
		case "getResourceComment":  // 根据rsid获取用户评论
			getResourceComment(request,response);
			break;
		case "sendAcComment":  // 根据aid获取用户评论
			sendAcComment(request,response);
			break;
		case "sendArtcComment":  // 根据artid获取用户评论
			sendArtcComment(request,response);
			break;
		case "sendRscComment":  // 根据artid获取用户评论
			sendRscComment(request,response);
			break;
		case "subQuestion":  // 写问题
			subQuestion(request,response);
			break;
		case "subExperience":  // 写经验贴
			subExperience(request,response);
			break;
		case "subResource":  // 写资料贴
			subResource(request,response);
			break;
		case "searchQuestion":  // 根据标题搜索问题
			searchQuestion(request,response);
			break;
		case "searchArticle":  // 根据标题搜索经验区
			searchArticle(request,response);
			break;
		case "searchResource":  // 根据标题搜索资料区
			searchResource(request,response);
			break;
		case "updateFocusNumByqid":  // 更新关注数
			updateFocusNumByqid(request,response);
			break;
		case "getFocusNumByqid":  // 查询关注数
			getFocusNumByqid(request,response);
			break;
		case "updateFocusNumByqid01":  // 更新关注数
			updateFocusNumByqid01(request,response);
			break;
		case "updateAnswerNumByqid":  // 更新点赞，收藏评论数
			updateAnswerNumByqid(request,response);
			break;
		case "getAnswerNumByqid":  // 更新点赞，收藏评论数
			getAnswerNumByqid(request,response);
			break;
		case "updateAnswerNumByqid01":  // 更新点赞，收藏评论数
			updateAnswerNumByqid01(request,response);
			break;
		}

	}


	private void updateAnswerNumByqid01(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		
		int aid = Integer.parseInt(request.getParameter("aid"));
		String mark_ = request.getParameter("mark_");
		switch(mark_) {
		case "heartAdd": { 
			int aLoveNum01 = Integer.parseInt(request.getParameter("aLoveNum"));
			int aLoveNum=aLoveNum01-1;
			ForumService fs = new ForumServiceImpl();
			boolean result = fs.updateAnswerNumByqid(aid,aLoveNum);
			Map<String,Boolean> map = new HashedMap<>();
			map.put("result",result);
			System.out.println("result:"+result);
			if(result) {
				out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
						Boolean>>("成功", true, map)));
			}else {
				out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
						Boolean>>("为空或失败", false, map)));
			}
			break;
		}
			
		case "starAdd":{
			int aForkNum01 = Integer.parseInt(request.getParameter("aForkNum"));
			int aForkNum=aForkNum01-1;
			ForumService fs = new ForumServiceImpl();
			boolean result = fs.updateAnswerNumByqid1(aid,aForkNum);
			Map<String,Boolean> map = new HashedMap<>();
			map.put("result",result);
			System.out.println("result:"+result);
			if(result) {
				out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
						Boolean>>("成功", true, map)));
			}else {
				out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
						Boolean>>("为空或失败", false, map)));
			}
			break;
		} 	
		
		case "dislikeAdd":{
			int aReportNum01 = Integer.parseInt(request.getParameter("aReportNum"));
			int aReportNum=aReportNum01-1;
			ForumService fs = new ForumServiceImpl();
			boolean result = fs.updateAnswerNumByqid2(aid,aReportNum);
			Map<String,Boolean> map = new HashedMap<>();
			map.put("result",result);
			System.out.println("result:"+result);
			if(result) {
				out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
						Boolean>>("成功", true, map)));
			}else {
				out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
						Boolean>>("为空或失败", false, map)));
			}
			break;
		} 
		
		case "discussAdd":{
			int aCommentNum01 = Integer.parseInt(request.getParameter("aCommentNum"));
			int aCommentNum=aCommentNum01-1;
			ForumService fs = new ForumServiceImpl();
			boolean result = fs.updateAnswerNumByqid3(aid,aCommentNum);
			Map<String,Boolean> map = new HashedMap<>();
			map.put("result",result);
			System.out.println("result:"+result);
			if(result) {
				out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
						Boolean>>("成功", true, map)));
			}else {
				out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
						Boolean>>("为空或失败", false, map)));
			}
			break;
		} 
		
		}
		
	}


	private void getAnswerNumByqid(HttpServletRequest request, HttpServletResponse response)  throws ServletException, IOException{
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		int aid = Integer.parseInt(request.getParameter("aid"));
//		String mark_ = request.getParameter("mark_");
//		switch(mark_) {
//		case "heartAdd":  
		ForumService fs = new ForumServiceImpl();
		Answer answer = new Answer();
		answer = fs.getAnswerNumByqid(aid);
		Map<String,Answer> map = new HashedMap<>();
		map.put("answer",answer);
//		System.out.println("answer:"+answer.getaLoveNum());
		if(answer!=null) {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					Answer>>("获取所有问题成功", true, map)));
		}else {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					Answer>>("获取所有问题为空或失败", false, map)));
		}
//		break;
//		}
	}


	private void updateAnswerNumByqid(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		
		int aid = Integer.parseInt(request.getParameter("aid"));
		String mark_ = request.getParameter("mark_");
		switch(mark_) {
		case "heartAdd": { 
			int aLoveNum01 = Integer.parseInt(request.getParameter("aLoveNum"));
			int aLoveNum=aLoveNum01+1;
			ForumService fs = new ForumServiceImpl();
			boolean result = fs.updateAnswerNumByqid(aid,aLoveNum);
			Map<String,Boolean> map = new HashedMap<>();
			map.put("result",result);
			System.out.println("result:"+result);
			if(result) {
				out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
						Boolean>>("成功", true, map)));
			}else {
				out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
						Boolean>>("为空或失败", false, map)));
			}
			break;
		}
		
		case "starAdd":{
			int aForkNum01 = Integer.parseInt(request.getParameter("aForkNum"));
			int aForkNum=aForkNum01+1;
			ForumService fs = new ForumServiceImpl();
			boolean result = fs.updateAnswerNumByqid1(aid,aForkNum);
			Map<String,Boolean> map = new HashedMap<>();
			map.put("result",result);
			System.out.println("result:"+result);
			if(result) {
				out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
						Boolean>>("成功", true, map)));
			}else {
				out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
						Boolean>>("为空或失败", false, map)));
			}
			break;
		} 	
		
		case "dislikeAdd":{
			int aReportNum01 = Integer.parseInt(request.getParameter("aReportNum"));
			int aReportNum=aReportNum01+1;
			ForumService fs = new ForumServiceImpl();
			boolean result = fs.updateAnswerNumByqid2(aid,aReportNum);
			Map<String,Boolean> map = new HashedMap<>();
			map.put("result",result);
			System.out.println("result:"+result);
			if(result) {
				out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
						Boolean>>("成功", true, map)));
			}else {
				out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
						Boolean>>("为空或失败", false, map)));
			}
			break;
		} 
		
		case "discussAdd":{
			int aCommentNum01 = Integer.parseInt(request.getParameter("aCommentNum"));
			int aCommentNum=aCommentNum01+1;
			ForumService fs = new ForumServiceImpl();
			boolean result = fs.updateAnswerNumByqid3(aid,aCommentNum);
			Map<String,Boolean> map = new HashedMap<>();
			map.put("result",result);
			System.out.println("result:"+result);
			if(result) {
				out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
						Boolean>>("成功", true, map)));
			}else {
				out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
						Boolean>>("为空或失败", false, map)));
			}
			break;
		} 
		
		}
	}


	private void updateFocusNumByqid01(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		
		int qid = Integer.parseInt(request.getParameter("qid"));
		int qFocusNum01 = Integer.parseInt(request.getParameter("qFocusNum"));
		int qFocusNum02=qFocusNum01-1;
		ForumService fs = new ForumServiceImpl();
		boolean result = fs.updateFocusNumByqid(qid,qFocusNum02);
		Map<String,Boolean> map = new HashedMap<>();
		map.put("result",result);
		System.out.println("result:"+result);
		if(result) {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					Boolean>>("成功", true, map)));
		}else {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					Boolean>>("为空或失败", false, map)));
		}
		
	}
	
	private void getFocusNumByqid(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		int qid = Integer.parseInt(request.getParameter("qid"));
		ForumService fs = new ForumServiceImpl();
		Question question = new Question();
		question = fs.getFocusNumByqid(qid);
//		System.out.println("-------");
//		System.out.println("11111"+question.getqFocusNum());
		Map<String,Integer> map = new HashedMap<>();
		map.put("question",question.getqFocusNum());
//		System.out.println("question:"+question);
		if(question!=null) {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					Integer>>("获取所有问题成功", true, map)));
		}else {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					Integer>>("获取所有问题为空或失败", false, map)));
		}
	}


	private void updateFocusNumByqid(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		
		int qid = Integer.parseInt(request.getParameter("qid"));
		int qFocusNum01 = Integer.parseInt(request.getParameter("qFocusNum"));
		int qFocusNum02=qFocusNum01+1;
		ForumService fs = new ForumServiceImpl();
		boolean result = fs.updateFocusNumByqid(qid,qFocusNum02);
		Map<String,Boolean> map = new HashedMap<>();
		map.put("result",result);
		System.out.println("result:"+result);
		if(result) {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					Boolean>>("成功", true, map)));
		}else {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					Boolean>>("为空或失败", false, map)));
		}
		
	}


	private void searchResource(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		
		String resource =request.getParameter("resource");
		ForumService fs = new ForumServiceImpl();
		ArrayList<Resource> resources = new ArrayList<Resource>();
		resources = fs.queryResourceByTitle(resource);
		Map<String,ArrayList<Resource>> map = new HashedMap<>();
		map.put("resources",resources);
		System.out.println("resources:"+resources);
		if(resources!=null) {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					ArrayList<Resource>>>("查询资料成功", true, map)));
		}else {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					ArrayList<Resource>>>("查询资料为空或失败", false, map)));
		}
		
	}


	private void searchArticle(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		
		String article =request.getParameter("article");
		ForumService fs = new ForumServiceImpl();
		ArrayList<Article> articles = new ArrayList<Article>();
		articles = fs.queryArticleByTitle(article);
		Map<String,ArrayList<Article>> map = new HashedMap<>();
		map.put("articles",articles);
		System.out.println("articles:"+articles);
		if(articles!=null) {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					ArrayList<Article>>>("查询问题成功", true, map)));
		}else {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					ArrayList<Article>>>("查询问题为空或失败", false, map)));
		}

		
	}


	private void searchQuestion(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		
		String question =request.getParameter("question");
		ForumService fs = new ForumServiceImpl();
		ArrayList<Question> questions = new ArrayList<Question>();
	    questions = fs.queryQuestionByTitle(question);
		Map<String,ArrayList<Question>> map = new HashedMap<>();
		map.put("questions",questions);
		System.out.println("questions:"+questions);
		if(questions!=null) {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					ArrayList<Question>>>("查询问题成功", true, map)));
		}else {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					ArrayList<Question>>>("查询问题为空或失败", false, map)));
		}

		
	}


	private void subResource(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		int userid = Integer.parseInt(request.getParameter("userid"));
		String title = request.getParameter("title");
		String content = request.getParameter("content");
		
		ForumService fs = new ForumServiceImpl();
		int suc = 0;
		suc = fs.subResource(title,userid,content);
		Map<String,Integer> map = new HashedMap<>();
		map.put("suc",suc);
		System.out.println("suc:"+suc);
		if(suc==1||suc==0) {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					Integer>>("成功", true, map)));
		}else {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					Integer>>("为空或失败", false, map)));
		}
		
	}


	private void subExperience(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		int userid = Integer.parseInt(request.getParameter("userid"));
		String title = request.getParameter("title");
		String content = request.getParameter("content");
		
		ForumService fs = new ForumServiceImpl();
		int suc = 0;
		suc = fs.subExperience(title,userid,content);
		Map<String,Integer> map = new HashedMap<>();
		map.put("suc",suc);
		System.out.println("suc:"+suc);
		if(suc==1||suc==0) {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					Integer>>("成功", true, map)));
		}else {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					Integer>>("为空或失败", false, map)));
		}
		
	}


	private void subQuestion(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		int userid = Integer.parseInt(request.getParameter("userid"));
		String title = request.getParameter("title");
		String content = request.getParameter("content");
		
		ForumService fs = new ForumServiceImpl();
		int suc = 0;
		suc = fs.subQuestion(title,userid,content);
		Map<String,Integer> map = new HashedMap<>();
		map.put("suc",suc);
		System.out.println("suc:"+suc);
		if(suc==1||suc==0) {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					Integer>>("成功", true, map)));
		}else {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					Integer>>("为空或失败", false, map)));
		}
		
	}


	private void sendRscComment(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		int userid = Integer.parseInt(request.getParameter("userid"));
		int rsid = Integer.parseInt(request.getParameter("rsid"));
		String rscComment = request.getParameter("rscComment");
		
		ForumService fs = new ForumServiceImpl();
		int suc = 0;
		suc = fs.sendRscComment(rsid,userid,rscComment);
		Map<String,Integer> map = new HashedMap<>();
		map.put("suc",suc);
		System.out.println("suc:"+suc);
		if(suc==1||suc==0) {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					Integer>>("成功", true, map)));
		}else {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					Integer>>("为空或失败", false, map)));
		}
		
	}


	private void sendArtcComment(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		int userid = Integer.parseInt(request.getParameter("userid"));
		int artid = Integer.parseInt(request.getParameter("artid"));
		String artcComment = request.getParameter("artcComment");
		
		ForumService fs = new ForumServiceImpl();
		int suc = 0;
		suc = fs.sendArtcComment(artid,userid,artcComment);
		Map<String,Integer> map = new HashedMap<>();
		map.put("suc",suc);
		System.out.println("suc:"+suc);
		if(suc==1||suc==0) {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					Integer>>("成功", true, map)));
		}else {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					Integer>>("为空或失败", false, map)));
		}
		
	}


	private void sendAcComment(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		int userid = Integer.parseInt(request.getParameter("userid"));
		int aid = Integer.parseInt(request.getParameter("aid"));
		String acComment = request.getParameter("acComment");
		
		ForumService fs = new ForumServiceImpl();
		int suc = 0;
		suc = fs.sendAcComment(aid,userid,acComment);
		Map<String,Integer> map = new HashedMap<>();
		map.put("suc",suc);
		System.out.println("suc:"+suc);
		if(suc==1||suc==0) {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					Integer>>("成功", true, map)));
		}else {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					Integer>>("为空或失败", false, map)));
		}
		
	}


	private void getResourceComment(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		
		int rsid = Integer.parseInt(request.getParameter("rsid"));
		ForumService fs = new ForumServiceImpl();
		ArrayList<ResourceComment> rscList = new ArrayList<ResourceComment>();
		rscList = fs.getResourceComment(rsid);
		Map<String,ArrayList<ResourceComment>> map = new HashedMap<>();
		map.put("rscList",rscList);
		if(rscList!=null) {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					ArrayList<ResourceComment>>>("根据mid获取单个Message成功", true, map)));
		}else {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					ArrayList<ResourceComment>>>("根据mid获取单个Message为空或失败", false, map)));
		}
		
	}


	private void getAllResource(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		ForumService fs = new ForumServiceImpl();
		ArrayList<Resource> rsList = new ArrayList<Resource>();
		rsList = fs.getAllResource();
		Map<String,ArrayList<Resource>> map = new HashedMap<>();
		map.put("rsList",rsList);
		System.out.println("rsList:"+rsList);
		if(rsList!=null) {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					ArrayList<Resource>>>("获取所有问题成功", true, map)));
		}else {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					ArrayList<Resource>>>("获取所有问题为空或失败", false, map)));
		}
		
	}

	
	private void getArticleComment(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		
		int artid = Integer.parseInt(request.getParameter("artid"));
		ForumService fs = new ForumServiceImpl();
		ArrayList<ArticleComment> artcList = new ArrayList<ArticleComment>();
		artcList = fs.getArticleComment(artid);
		Map<String,ArrayList<ArticleComment>> map = new HashedMap<>();
		map.put("artcList",artcList);
		if(artcList!=null) {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					ArrayList<ArticleComment>>>("根据artid获取单个Message成功", true, map)));
		}else {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					ArrayList<ArticleComment>>>("根据artid获取单个Message为空或失败", false, map)));
		}
		
	}


	private void getAllArticle(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		ForumService fs = new ForumServiceImpl();
		ArrayList<Article> artList = new ArrayList<Article>();
		artList = fs.getAllArticle();
		Map<String,ArrayList<Article>> map = new HashedMap<>();
		map.put("artList",artList);
		System.out.println("artList:"+artList);
		if(artList!=null) {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					ArrayList<Article>>>("获取所有问题成功", true, map)));
		}else {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					ArrayList<Article>>>("获取所有问题为空或失败", false, map)));
		}
		
	}


	private void getAnswerComment(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		
		int aid = Integer.parseInt(request.getParameter("aid"));
		ForumService fs = new ForumServiceImpl();
		ArrayList<AnswerComment> acList = new ArrayList<AnswerComment>();
		acList = fs.getAnswerComment(aid);
		Map<String,ArrayList<AnswerComment>> map = new HashedMap<>();
		map.put("acList",acList);
		if(acList!=null) {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					ArrayList<AnswerComment>>>("根据aid获取单个Message成功", true, map)));
		}else {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					ArrayList<AnswerComment>>>("根据aid获取单个Message为空或失败", false, map)));
		}
		
	}


	private void getAnswerByqid(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		int qid = Integer.parseInt(request.getParameter("qid"));
		ForumService fs = new ForumServiceImpl();
		ArrayList<Answer> aList = new ArrayList<Answer>();
		aList = fs.getAnswerByqid(qid);
		Map<String,ArrayList<Answer>> map = new HashedMap<>();
		map.put("aList",aList);
		System.out.println("aList:"+aList);
		if(aList!=null) {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					ArrayList<Answer>>>("获取所有问题成功", true, map)));
		}else {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					ArrayList<Answer>>>("获取所有问题为空或失败", false, map)));
		}
		
	}


	private void getAllQuestion(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		ForumService fs = new ForumServiceImpl();
		ArrayList<Question> qList = new ArrayList<Question>();
		qList = fs.getAllQuestion();
		Map<String,ArrayList<Question>> map = new HashedMap<>();
		map.put("qList",qList);
		System.out.println("qList:"+qList);
		if(qList!=null) {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					ArrayList<Question>>>("获取所有问题成功", true, map)));
		}else {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					ArrayList<Question>>>("获取所有问题为空或失败", false, map)));
		}
		
	}

}



/*
*      
*          ┌─┐       ┌─┐
*       ┌──┘ ┴───────┘ ┴──┐
*       │                 │
*       │       ───       │
*       │  ─┬┘       └┬─  │
*       │                 │
*       │       ─┴─       │
*       │                 │
*       └───┐         ┌───┘
*           │         │
*           │         │
*           │         │
*           │         └──────────────┐
*           │                        │
*           │                        ├─┐
*           │                        ┌─┘    
*           │                        │
*           └─┐  ┐  ┌───────┬──┐  ┌──┘         
*             │ ─┤ ─┤       │ ─┤ ─┤         
*             └──┴──┘       └──┴──┘ 
*                 神兽保佑 
*                 代码无BUG! 
*/
